package com.mdhw.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mdhw.common.base.PageData;
import com.mdhw.common.enums.StatusEnum;
import com.mdhw.config.R;
import com.mdhw.system.dao.SysLogDao;
import com.mdhw.system.entity.SysKdCode;
import com.mdhw.system.entity.SysLog;
import com.mdhw.system.service.SysLogService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName SysLogServiceImpl.java
 * @Description TODO
 * @createTime 2022年03月28日 17:51:00
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogDao, SysLog> implements SysLogService {


    @Override
    public R<PageData<SysLog>> getList(Integer pageNo, Integer pageSize, String keyword, String startTime, String endTime) {
        LambdaQueryWrapper<SysLog> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SysLog::getStatus, StatusEnum.OK.getCode());
        if(StringUtils.hasText(keyword)){
            lqw.and(c -> c.like(SysLog::getModuleName, keyword)
                    .or().like(SysLog::getModuleValue,keyword)
                    .or().like(SysLog::getParams,keyword)
                    .or().like(SysLog::getMethodName, keyword));
        }
        if(StringUtils.hasText(startTime) && StringUtils.hasText(endTime)){
            lqw.ge(SysLog::getCreateDate, startTime);
            lqw.le(SysLog::getCreateDate, endTime);
        }
        lqw.orderByDesc(SysLog::getCreateDate);
        Page<SysLog> page = new Page<>(pageNo, pageSize);
        this.page(page,lqw);
        PageData<SysLog> pageData = PageData.plusPageToPageData(page);
        return R.success(pageData);
    }
}
